#!/usr/bin/python
# -*- coding: utf-8 -*-
# Created by binhou.li on 02/03/2018
# @Copyright

import os
import config
import utils

class infoExtractor():
    """
    extract rtv info
    """
    def __init__(self, store_path):
        self.store_path = store_path
        self.info = {}
        if os.path.exists(store_path):
            self.plist = store_path.rstrip('/').split('/')
        else:
            logging.error(store_path + ' does not exist!')
            self.plist = []

    def _get_region_eom(self):
        if len(self.plist) != 0:
            sql = 'select count(*) from dcs.webapp_raw_file where region_oem_id in \
                (select id from webapp_region_oem where region_name=\'%s\')' % self.plist[-2]
            sql_res = utils.exec_dml_sql(sql)
            if sql_res == '0':
                raise Exception('no region_oem called %s' %self.plist[-2])
            else:
                self.info['region_oem'] = self.plist[-2]

    def _get_fg_complete(self):
        count = 0
        flist = os.listdir(self.store_path)
        for f in flist:
            if f.endswith('.rtv'):
                count += 1
            elif f.endswith('.imu'):
                count += 1
            elif f.endswith('.gps'):
                count += 1
        if count == 3:
            self.info['fg_complete'] = 1
        else:
            self.info['fg_complete'] = 0

    def _get_cam_info(self):
        pass








